package csci3033.RecordaNote;

import java.io.Serializable;
//import java.util.List;
import java.util.ArrayList;
import java.util.Calendar;

@SuppressWarnings("serial")
public class Marker implements Serializable {
	
	private String 		name;
	private Long		time;
	private String		notes;
	
	private Calendar	date;
	private String		timestamp;
	private String		markerTimestamp;
	
	private int 		markerMin;
	private int 		markerSec;
	private int 		markerHr;
	private long 		markerMs;
	private boolean 	isRecording;
	
	//private ArrayList<Marker> markers;
	
	public Marker() {
		
	}
	public Marker(long t , int size, boolean isRecording) {
		this.time = t;
		
		this.isRecording = isRecording;
		
		//this.name = time.toString();
		//markers.size();
		size+=1;
		this.name = "Marker " + size;
		this.date = Calendar.getInstance();
		setMarkerTimestamp(t, isRecording);
		// TODO Convert nanoseconds to a better format
	}
	/*
	public Marker(long t , int size) {
		this.time = t;
		//this.name = time.toString();
		//markers.size();
		size+=1;
		this.name = "Marker " + size;
		this.date = Calendar.getInstance();
		setMarkerTimestamp();
		// TODO Convert nanoseconds to a better format
	}
	*/
	public void setName(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}
	
	public void setNotes(String notes) {
		this.notes = notes;
	}
	
	public String getNotes() {
		return notes;
	}
	
	public long getTime() {
		return time;
	}
	public void setTimestamp() {
		String amOrPm;
		int	   hour   = date.get(Calendar.HOUR);
		int    minute = date.get(Calendar.MINUTE);
		int    second = date.get(Calendar.SECOND);
		String minuteStr = ("" + minute);
		String secondStr = ("" + second);
		
		if (date.get(Calendar.AM_PM) == 0) {
			amOrPm = "AM";
		}
		else {
			amOrPm = "PM";
		}
		
		if (hour == 0 ) {
			hour = 12;
		}
		
		if (minute < 10) {
			minuteStr = ("0" + minute);
		}
		if (second < 10) {
			secondStr = ("0" + second);
		}
		
		this.timestamp = ("" + hour + ":"
							+ minuteStr + ":"
							+ secondStr + " "
							+ amOrPm + "  "
							+ (date.get(Calendar.MONTH) + 1) + "/"
							+ date.get(Calendar.DAY_OF_MONTH) + "/"
							+ date.get(Calendar.YEAR));
	}
	public String getTimestamp() {
		return timestamp;
	}
	public void setMarkerTimestamp(long t, boolean isRecording) {
		String tempStr;
		if (isRecording) {
			long millis = t;
		    int seconds = (int) (millis / 1000);
		    int minutes = seconds / 60;
		    int hours 	= minutes / 60;
		    seconds     = seconds % 60;
		    
		    markerMs = millis;
		    markerSec = seconds;
		    markerMin = minutes;
		    markerHr = hours;
		    
		    millis = millis % 1000;
		    
		    tempStr =String.format("%d:%02d:%02d.%d", hours, minutes, seconds, millis);
		}
		else {
			String amOrPm;
			int	   hour   = date.get(Calendar.HOUR);
			int    minute = date.get(Calendar.MINUTE);
			int    second = date.get(Calendar.SECOND);
			String minuteStr = ("" + minute);
			String secondStr = ("" + second);
			
			if (date.get(Calendar.AM_PM) == 0) {
				amOrPm = "AM";
			}
			else {
				amOrPm = "PM";
			}
			
			if (hour == 0 ) {
				hour = 12;
			}
			
			if (minute < 10) {
				minuteStr = ("0" + minute);
			}
			if (second < 10) {
				secondStr = ("0" + second);
			}
			
			tempStr = ("" + hour + ":"
								+ minuteStr + ":"
								+ secondStr + " "
								+ amOrPm + "  "
								+ (date.get(Calendar.MONTH) + 1) + "/"
								+ date.get(Calendar.DAY_OF_MONTH) + "/"
								+ date.get(Calendar.YEAR));
		}
		this.markerTimestamp = tempStr;
	}
	public String getMarkerTimestamp() {
		return markerTimestamp;
	}
}
